package com.qxy.dydemo;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class MovieList extends AppCompatActivity {
    RecyclerView mRecyclerView;
    MyAdapter mMyAdapter ;
    List<News> mNewsList = new ArrayList<>();
    List<MovieItem> mMovieItemList = new ArrayList<>();
    private Button toTVListButton;
    private Button toShowListButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_movie_list);
        toTVListButton= (Button)findViewById(R.id.button);
        toShowListButton= (Button)findViewById(R.id.button2);
        toShowListButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(MovieList.this,ShowList.class);
                startActivity(intent);
            }
        });

        toTVListButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(MovieList.this,TVList.class);
                startActivity(intent);
            }
        });
        mRecyclerView = findViewById(R.id.recyclerView);
        // 构造一些数据
        /*for (int i = 0; i < 50; i++) {
            News news = new News();
            news.title = "标题" + i;
            news.content = "内容" + i;
            mNewsList.add(news);
        }*/


        for (int i = 0; i < 50; i++) {
            MovieItem movieItem = new MovieItem();
            movieItem.director = "导演" + i;
            movieItem.area = "内容" + i;
            movieItem.hotness = "热度" + i;
            movieItem.movie_name = "名字" + i;
            movieItem.actors = "主演" + i;
            movieItem.release_date = "上映日期" + i;
            mMovieItemList.add(movieItem);
        }





        mMyAdapter = new MyAdapter();
        mRecyclerView.setAdapter(mMyAdapter);
        LinearLayoutManager layoutManager = new LinearLayoutManager(MovieList.this);
        mRecyclerView.setLayoutManager(layoutManager);



    }






    class MyAdapter extends RecyclerView.Adapter<MyViewHolder> {

        @NonNull
        @Override
        public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = View.inflate(MovieList.this, R.layout.movielist_item, null);
            MyViewHolder myViewHolder = new MyViewHolder(view);
            return myViewHolder;
        }

        @Override
        public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        /*    News news = mNewsList.get(position);
            holder.mTitleTv.setText(news.title);
            holder.mTitleContent.setText(news.content);*/
              MovieItem movieItem= mMovieItemList.get(position);
              holder.mName.setText(movieItem.movie_name);
              holder.mDirector.setText(movieItem.director);
              holder.mActor.setText(movieItem.actors);
              holder.mHotness.setText(movieItem.hotness);
              holder.mTime.setText(movieItem.release_date);

        }

        @Override
        public int getItemCount() {
            return mMovieItemList.size();
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView mName;
        TextView mDirector;
        TextView mActor;
        TextView mHotness;
        TextView mTime;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            mName = itemView.findViewById(R.id.movie1);
            mDirector = itemView.findViewById(R.id.movie5);
            mActor= itemView.findViewById(R.id.movie3);
            mHotness= itemView.findViewById(R.id.movie2);
            mTime=itemView.findViewById(R.id.movie4);
        }
    }
}

